﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：回车
 */

var acceptClick;
var keyValue = request('keyValue');
var processId = '';
var bootstrap = function ($, learun) {
    "use strict";

    var page = {
        init: function () {
            page.initleft();
            page.bind();
            page.initData();
        },
        bind: function () {


        },
        initleft: function () {
            $('#lr_left_list li').on('click', function () {
                var $this = $(this);
                var $parent = $this.parent();
                $parent.find('.active').removeClass('active');
                $this.addClass('active');

                var data_value = $this.attr('data-value');

                switch (data_value) {
                    case "1":
                        $("#tab_basic").show();
                        $("#tab_bill").hide();
                        break;
                    case "4":
                        $("#tab_basic").hide();
                        $("#tab_bill").show();
                        break;
                    default:
                        break;
                }
            });
        },
        initData: function () {
            if (!!keyValue) {
                $.lrSetForm(config.base_server() + 'cars/findById?id=' + keyValue, function (data) {
                    if (!!data.processId) {
                        processId = data.processId;
                        $("#processId").val(processId);
                        $("#myiframe").attr("src", config.base_server() + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?hideRightPanel=1&tabIframeId=' + processId + '&type=100' + '&processId=' + processId + '&taskId=&access_token=' + config.getToken().access_token)
                    } else {
                        $("#lr_left_list li[data-value='4']").hide();
                    }
                });
            }
            //var processId = 'bdc1cc22-cdc7-30c9-2d85-eaaf26fe7a32';
        }
    };

    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#tab_basic').lrValidform()) {
            return false;
        }
        var postData = $('#tab_basic').lrGetFormData(keyValue);
        postData.id = $("#processId").val();
        $.lrSaveForm(config.base_server() + 'carapply1s/back?access_token=' + config.getToken().access_token + '&keyValue=' + keyValue, JSON.stringify(postData), function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}